import org.omg.CORBA.ObjectHelper;

import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;


//顺序队列的意义在哪？？？？？？
public class MySeqQueue {
    private int maxSize = 10;
    private int size;
    private int front;//队头
    private int rear;//队尾
    private Object[] data;


    public MySeqQueue() {
        initiate();
    }

    public void initiate() {
        data = new Object[maxSize];
        size = front = rear = 0;

    }

    public MySeqQueue(int size) {
        data = new Object[size];
        maxSize =size;
        front = rear = 0;
        this.size = front = rear = 0;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public int getSize() {
        return size;
    }

    public boolean isFull() {
        return size > 0 && rear == maxSize;
    }

    public Object getFront() {
        if (isEmpty()) {
            return null;
        }

        //seqQueueArray[rear]，用取余方式不会数组越界
        return data[rear-1];
    }

    public void queueAppend(Object obj) throws Exception {
        if (isFull()) {
            throw new Exception("队列已满！");
        }
        data[rear] =obj;
//        rear = (rear +1 )%maxSize;取余方式添加
        rear ++;
        size++;
    }

    public Object queueDelete() throws Exception {
        if (isEmpty()){
            throw new Exception("队列已空！");
        }
//        front = (front +1)%maxSize;取余方式删除
        size --;
        rear --;
        return data[rear];
    }
}
